<template>
  <el-dialog
    title="添加步骤"
    :close-on-click-modal="false"
    :visible.sync="visible"
  >
    <el-form
      :model="dataForm"
      ref="dataForm"
      @keyup.enter.native="dataFormSubmit()"
      v-for="step in dataForm.StepList"
      :key="step.stepId"
    >
      <el-form-item prop="stepSum">
        <span slot="label" style="font-size:20px; font-weight:bold;">步骤{{ step.stepSum }}</span>
      </el-form-item>
      <el-form-item prop="stepDesc">
        <el-input type="textarea" v-model="step.stepDesc" placeholder="菜单步骤"></el-input>
      </el-form-item>
      <el-form-item prop="stepImg">
        <el-upload
          class="avatar-uploader"
          action="https://jsonplaceholder.typicode.com/posts/"
          :show-file-list="false"
          :on-success="handleAvatarSuccess"
          :before-upload="beforeAvatarUpload"
        >
          <img v-if="step.stepImg" :src="step.stepImg" style="width: 150px; height: 100px" class="avatar" />
          <i v-else class="el-icon-plus avatar-uploader-icon"></i>
        </el-upload>
      </el-form-item>
    </el-form>

    <el-button round @click="addStep">添加</el-button>
    <el-button round @click="deleteStep">删除</el-button>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
export default {
  data() {
    return {
      visible: false,
      fits: ["fill", "contain", "cover", "none", "scale-down"],
      dataForm: {
        dishId: 1,
        totalSteps: 5,
        StepList: [
          {
            stepId: 0,
            stepSum: 1,
            stepDesc:
              "1.姜，蒜洗净切片；葱切葱花；菠萝去皮洗净同切成拇指大小的滚刀块备用。",
            stepImg:
              "http://pic.dachuang.pengdong.top/imgs/2022/03/5af16fb8bd2b0948.jpg",
          },
          {
            stepId: 1,
            stepSum: 2,
            stepDesc:
              "2.里脊肉洗净，切成拇指大小的滚刀块，放入5克盐，10克料酒，少许葱姜，腌制15分钟。",
            stepImg:
              "http://pic.dachuang.pengdong.top/imgs/2022/03/5af16fb8bd2b0948.jpg",
          },
          {
            stepId: 2,
            stepSum: 3,
            stepDesc:
              "3.用白糖50克，白醋30克，盐5克，淀粉10克，加少许清水，调成料汁备用。",
            stepImg:
              "http://pic.dachuang.pengdong.top/imgs/2022/03/5d24e539f332cdd3.jpg",
          },
          {
            stepId: 3,
            stepSum: 4,
            stepDesc: "4.锅内放水，水烧开，放入菠萝焯一下，捞出沥干水分备用。",
            stepImg:
              "http://pic.dachuang.pengdong.top/imgs/2022/03/61d4a33790e181c3.jpg",
          },
          {
            stepId: 4,
            stepSum: 5,
            stepDesc: "5.将腌制好的里脊肉，用淀粉均匀。",
            stepImg:
              "http://pic.dachuang.pengdong.top/imgs/2022/03/694b8a3c6587bcb1.jpg",
          }
        ]
      }
    };
  },
  methods: {
    // addStep 添加 步骤
    addStep() {},
    deleteStep() {},
    init(id) {
      this.dataForm.dishId = id || 0;
      this.visible = true;
      this.$nextTick(() => {
        // this.$refs["dataForm"].resetFields();
        if (this.dataForm.dishId) {
          this.$http({
            url: this.$http.adornUrl(`/menu/dish/info/${this.dataForm.dishId}`),
            method: "get",
            params: this.$http.adornParams()
          }).then(({ data }) => {
            if (data && data.code === 0) {
              this.dataForm.dishName = data.dish.dishName;
            }
          });
        }
      });
    }
  }
};
</script>
<style>
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
</style>